package com.yunhe.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yunhe.bean.CommodityClassify;
import com.yunhe.test.test;

/**
 * Servlet implementation class ChangeClassify_Servlet
 */
@WebServlet("/ChangeClassify_Servlet")
public class ChangeClassify_Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChangeClassify_Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		// TODO Auto-generated method stub
		test te=new test();
		response.setCharacterEncoding("utf-8");
		request.setCharacterEncoding("utf-8");
		String str=""; 
		str=request.getParameter("cpid");
		System.out.println(str);
	    
	    //对大分类表操作
	    if(str==null || "".equals(str)){
	    	String bigid="";
	    	String bigname="";
	    	bigid= request.getParameter("bigid");
	    	int bigId=Integer.decode(bigid);
	    	bigname= request.getParameter("bigname");
	    	CommodityClassify cc=new CommodityClassify();
	    	cc.setBig_id(bigId);
	    	cc.setBig_name(bigname);
	    	System.out.println(cc);
	    	te.ChangeBigClassify(cc); 	
	    }
	    //对小分类表操作
	    else{
	    	String smallname=request.getParameter("cname");
	    	int smallId=0;
			if(request.getParameter("smallid")!=null){
				 smallId=Integer.decode(request.getParameter("smallid"));
			}
	    	CommodityClassify cc=new CommodityClassify();
	    	int bigid=0;
	    	if(str!=null){
	    		bigid=Integer.decode(str);
			}
	    	cc.setBig_id(bigid);
	    	cc.setSmall_id(smallId);
	    	cc.setSmall_name(smallname);
	    	System.out.println(cc);
	    	te.ChangeSmallClassify(cc);
	    }
	    response.sendRedirect("manage/productClass.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
